package com.hd.boot.service.impl;

import com.hd.boot.mapper.FilmMapper;
import com.hd.boot.pojo.Film;
import com.hd.boot.service.FilmService;
import com.hd.boot.util.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class FilmServiceImpl implements FilmService {
    @Autowired
    private FilmMapper filmMapper;
    @Override
    public JsonData allFilm() {
        List<Film> films=filmMapper.allFilm();
        return JsonData.buildSuccess(films,"success");
    }

    @Override
    public JsonData delFilm(int fId) {
        int i=filmMapper.delFilm(fId);
        if (i>0){
            return JsonData.buildSuccess("成功");
        }
        return JsonData.buildError("失败");
    }

    @Override
    public JsonData saveFilm(Film film) {
        int i=0;
        if (film.getfId()==null){
            i=filmMapper.saveFilm(film);
        }else {

            i=filmMapper.enidFilm(film);
        }
        if (i>0){
            return JsonData.buildSuccess("成功");
        }
        return JsonData.buildError("失败");
    }
}
